import axios from "axios";
import store from "@/store/index"

//请求拦截器
axios.interceptors.request.use((config) =>{
	let _token = store.state.common._token;
	if (_token) {
	    config.headers["Authorization"] = _token;
	}
	// 放行
	return config;
})

//响应拦截器
axios.interceptors.response.use((ret)=>{
	if(ret.data._token){
		//存到vuex中
		store.commit("common/setToken",ret.data._token)
	}
	
	return ret.data || ret;
})


//导出
export default axios
